package com.mindbook.vip.gawxchatinfo.controller.user;

import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author wxb
 * @Datatime 2022/4/25 17:41
 * @Descript 认证结果控制器
 */
@Api(tags = "认证结果")
@RestController
public class AuthenticationController {


    //跳转到登录页面
    @CrossOrigin
    @GetMapping("login")
    @ApiOperation(value = "用户未认证或用户认证失败后再次跳转的接口")
    public Result login(){
        return ResultUtils.genErrorResult(ResultEnum.SHIRO_CURRENT_USER_NOT_LOGIN);
    }

    @CrossOrigin
    @GetMapping("unauthorizedUrl")
    @ApiOperation(value = "用户未认证")
    public Result unauthorizedUrl(){
        return ResultUtils.genErrorResult(ResultEnum.SHIRO_UNAUTHORIZED_EXCEPTION);
    }

    @CrossOrigin
    @GetMapping("success")
    @ApiOperation(value = "用户认证成功跳转地址,无论是前端还是后端")
    public Result loginSuccess(){
        System.out.println("进入了登录成功的view中");
        Session session = SecurityUtils.getSubject().getSession();
        return ResultUtils.genSuccessResult(session);
    }
}
